utils.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { pagePathUtils } from '@growi/core/dist/utils';
  2. import ExtensibleCustomError from 'extensible-custom-error';
  3. import { SupportedAction } from '~/interfaces/activity';
  4. import type { SupportedActionType } from '~/interfaces/activity';
  5. import type { IPageToShowRevisionWithMeta } from './types';
  6. export class MultiplePagesHitsError extends ExtensibleCustomError {
  7. pagePath: string;
  8. constructor(pagePath: string) {
  9. super(`MultiplePagesHitsError occured by '${pagePath}'`);
  10. this.pagePath = pagePath;
  11. }
  12. }
  13. export const getAction = (props: {
  14. isNotCreatable: boolean;
  15. isForbidden: boolean;
  16. isNotFound: boolean;
  17. pageWithMeta?: IPageToShowRevisionWithMeta | null;
  18. }): SupportedActionType => {
  19. if (props.isNotCreatable) {
  20. return SupportedAction.ACTION_PAGE_NOT_CREATABLE;
  21. }
  22. if (props.isForbidden) {
  23. return SupportedAction.ACTION_PAGE_FORBIDDEN;
  24. }
  25. if (props.isNotFound) {
  26. return SupportedAction.ACTION_PAGE_NOT_FOUND;
  27. }
  28. if (pagePathUtils.isUsersHomepage(props.pageWithMeta?.data.path ?? '')) {
  29. return SupportedAction.ACTION_PAGE_USER_HOME_VIEW;
  30. }
  31. return SupportedAction.ACTION_PAGE_VIEW;
  32. };